
package com.android.matmanual;

import android.app.Activity;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnTouchListener;
import android.widget.TextView;
public class MultipleTPTest extends BaseActivity implements OnTouchListener{
	TextView pointTv;
	TextView successTv;
	WakeLock mWakeLock;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.multipletptest);
		setTitle(R.string.multipletp_title);
		
	    PowerManager pm =
		           (PowerManager) getSystemService(POWER_SERVICE); 
	    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, 
		          "XYTEST"); 
		mWakeLock.acquire(); 
		
		pointTv=(TextView)findViewById(R.id.point);
		successTv=(TextView)findViewById(R.id.success);
		pointTv.setText(R.string.zero);
	}
	
	public boolean onTouch(View arg0, MotionEvent arg1) {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
        pointTv.setText(new Integer(event.getPointerCount()).toString());
        if(event.getPointerCount()>=5){
        	successTv.setVisibility(View.VISIBLE);
        	successTv.setText(R.string.success);
        }
        if(event.getAction()==MotionEvent.ACTION_UP){
        	if(event.getPointerCount()==1){
        		pointTv.setText(R.string.zero);
        	}
        	
		}
		return super.onTouchEvent(event);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		int result = TestControl.GetKeyEvent(keyCode);
		if (result != TestControl.DO_NOTHING) {
			setResult(result);
			finish();
	    }
	    return true;
	}
	    @Override
	    protected void onDestroy() {
	    	// TODO Auto-generated method stub
			if(mWakeLock!=null)
			{
				mWakeLock.release(); 
				mWakeLock = null;
			}
	    	super.onDestroy();
	    }	 
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
       finish();
		super.onStop();
	}

	@Override
	public void onAttachedToWindow() 
	{
		// TODO Auto-generated method stub
		super.onAttachedToWindow();
		this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
	}
}
		 